home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Beginner: Some Questions
- Date: Tue, 16 Apr 1996 16:10:20 -0400
- Organization: Datalytics, Inc.
- Message-ID: <3173FEAC.637C@datalytics.com>
- References: <N.041596.214427.72@slipper163167.bcs.iafrica.com>
- NNTP-Posting-Host: 204.62.224.241
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- herbi@iafrica.com wrote:
- >
- > Hi
- > I am a C++ beginner. I programmed in T.Pascal, and now i need someting new. The
- > basic commands in Pascal is the same as in C++.
- > I have some questions, i know how to do it in Pascal,but not in C++. If you
- > can, could you perhaps answer them for me.
- >
- > 1) How do you repeat a statement for a certen amout of times, or until a key is
- > pressed?
-
- The first half of this is a C question, the second half is
- OS-specific. Let me answer the first half.
-
- To loop so long as a condition holds true, use while or do loop.
- The former tests before executing the loop code, the latter
- after. For example,
-
- while (x > 25)
- {
- // do something here
- }
-
- or
-
- do
- {
- // do something here
- } while (x > 25);
-
- > 2) How do you activate the mouse or mouse driver?
-
- This is OS-specific; it isn't a C++ question.
-
- > 3) How do you open a text file, input data or read data?
-
- The "standard" C++ way to open a file is with the iostreams
- library. You can write your own C++ class to encapsulate your
- OS's file I/O commands and you can step back to C's STDIO
- functions (like fopen, fread, fclose, etc.).
-
- Here's how to open a text file and read a line at a time:
-
- #include <fstream.h> // ifstream
-
- void f(void)
- {
- ifstream in("filename");
- const int MAX_BUFFER_LENGTH = 80;
- char vBuffer
- [
- MAX_BUFFER_LENGTH
- + 1
- ];
- while (in.getline(
- vBuffer,
- MAX_BUFFER_LENGTH))
- {
- // handle the contents of vBuffer as desired
- }
- }
-
- > 4) How do you get 256 colors in C++?
-
- This is OS and environment (e.g., MS Windows or X Windows)
- specific.
-
- > If you know of a site or ftp which have c++ source files or anything to do with
- > C++ programming, could you give it to me please.
-
- There are many. Do a yahoo or search.com (or other search
- engine) search for them.
-
- --
- Rob Stewart | My opinions are generally my own. They do
- Datalytics, Inc.| not necessarily reflect those of my employer.
-